﻿Imports conn
Imports MySql.Data.MySqlClient
Public Class Main_Server
    Dim ball As Integer = 0
    Private Sub Main_Server_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        details.isauthed = False
        For i = 0 To 89
            details.numbers(i) = 0
        Next
    End Sub
    Sub tab_change() Handles TabControl1.SelectedIndexChanged
        If TabControl1.SelectedIndex > 0 Then
            If details.isauthed = False Then
                TabControl1.SelectedIndex = 0
                MsgBox("You need to be logged in to do that.")
            End If
        End If
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlogin.Click
        connection.conn()
        Dim command = New MySqlCommand
        command.CommandText = "SELECT * FROM `members` WHERE `username` = '" & txtusername.Text.ToLower & "' AND `password` = '" & functions.getMd5Hash(txtpass.Text) & "' " 'Query to exectue.
        command.Connection = connection.MyADOConnection
        Dim read = command.ExecuteReader
        read.Read() 'Opens the reader.
        If read.HasRows Then
            If read.GetString(3) >= 3 Then
                details.username = read.GetString(1) 'Gets the data from the database
                details.password = txtpass.Text 'Saves the password
                details.isauthed = True 'Allows user to access tabs
                read.Close() 'Closes the reader
                conn.connection.MyADOConnection.Close() 'Closes the database connection
            Else
                MsgBox("You do not have access to this section", MsgBoxStyle.Critical)
            End If
        Else
            MsgBox("Sorry there has been a problem logging you in.", MsgBoxStyle.Critical)
            MsgBox("Check your details and try again.", MsgBoxStyle.Critical)
            read.Close() 'Closes the reader
            connection.MyADOConnection.Close() 'Closes the database connection
        End If
    End Sub
    Private Sub gen_num_Tick() Handles gen_num.Tick
        Dim r = Rnd() * 90
        'If details.numbers(i) = r Then
        'gen_num_Tick()
        'ElseIf details.numbers(i) = 0 Then
        'details.numbers(i) = r
        'Exit Sub
        'End If
        'Next
    End Sub
    Private Sub Button1_Click_1() Handles Button1.Click
        For i = 0 To 89
            MsgBox(i & " " & details.numbers(i))
            Next
    End Sub
End Class
